﻿ 
using AntDesign.ProLayout;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AntDesign;
using Microsoft.Extensions.Configuration;
using Volo.Abp.MultiTenancy;
using System;

namespace ERP.BlazorServer
{
    public partial class RightContent
    {
      //  private CurrentUser _currentUser = new CurrentUser();
      //  private NoticeIconData[] _notifications = { };
      //  private NoticeIconData[] _messages = { };
     //   private NoticeIconData[] _events = { };
        private int _count = 0;

        private List<AutoCompleteDataItem<string>> DefaultOptions { get; set; } = new List<AutoCompleteDataItem<string>>
        {
            new AutoCompleteDataItem<string>
            {
                Label = "umi ui",
                Value = "umi ui"
            },
            new AutoCompleteDataItem<string>
            {
                Label = "Pro Table",
                Value = "Pro Table"
            },
            new AutoCompleteDataItem<string>
            {
                Label = "Pro Layout",
                Value = "Pro Layout"
            }
        };

        public List< AvatarMenuItem> AvatarMenuItems { get; set; } = new List<AvatarMenuItem>
        {
            //new() { Key = "center", IconType = "user", Option = "个人中心"},
           // new() { Key = "setting", IconType = "setting", Option = "个人设置"},
           // new() { IsDivider = true },
            new() { Key = "logout", IconType = "logout", Option = "退出登录"}
        };

  

       // [Inject] protected IUserService UserService { get; set; }
      // [Inject] protected IProjectService ProjectService { get; set; }
        [Inject] protected MessageService MessageService { get; set; }




        [Inject] protected IConfiguration Configuration { get; set; }
        [Inject] protected NavigationManager NavigationManager { get; set; }
        [Inject]   Volo.Abp.Users.ICurrentUser CurrentUser { get; set; }
        [Inject]   ICurrentTenant CurrentTenant { get; set; }

      /*
        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();
            SetClassMap();
           // _currentUser = await UserService.GetCurrentUserAsync();
            //var notices = await ProjectService.GetNoticesAsync();
         //   _notifications = notices.Where(x => x.Type == "notification").Cast<NoticeIconData>().ToArray();
          //  _messages = notices.Where(x => x.Type == "message").Cast<NoticeIconData>().ToArray();
          //  _events = notices.Where(x => x.Type == "event").Cast<NoticeIconData>().ToArray();
          //  _count = notices.Length;
        }
        */
        protected void SetClassMap()
        {
            //ClassMapper
            //    .Clear()
            //    .Add("right");
        }

        public void HandleSelectUser(MenuItem item)
        {
            switch (item.Key)
            {
                case "center":
                    NavigationManager.NavigateTo("/account/center");
                    break;
                case "setting":
                    NavigationManager.NavigateTo("/account/settings");
                    break;
                case "logout":
                    //{Uri.EscapeDataString(NavigationManager.Uri)}
                    //http://localhost:8081/account/logout?returnUrl=~%2Faccount%2Flogin%3FreturnUrl%3Dhttp%3A%2F%2Flocalhost%3A8088

                    string identityServerUrl = Configuration["AuthServer:Authority"] ?? "";
                    string selfUrl = Configuration["App:SelfUrl"] ?? "";
                    string ClientId = Configuration["AuthServer:ClientId"] ?? "";
                    string returnUrl = Uri.EscapeDataString(  $"~/account/login?returnUrl=" + Uri.EscapeDataString($"{NavigationManager.Uri}"));
                    NavigationManager.NavigateTo($"{identityServerUrl}/account/logout?returnUrl={returnUrl}", true);
                    break;
            }
        }

        public void HandleSelectLang(MenuItem item)
        {
        }

        public async Task HandleClear(string key)
        {
            switch (key)
            {
                case "notification":
                 //   _notifications = new NoticeIconData[] { };
                    break;
                case "message":
                   // _messages = new NoticeIconData[] { };
                    break;
                case "event":
                  //  _events = new NoticeIconData[] { };
                    break;
            }
            await MessageService.Success($"清空了{key}");
        }

        public async Task HandleViewMore(string key)
        {
            await MessageService.Info("Click on view more");
        }
    }
}